06. 练习:变量和赋值运算符
练习:赋值和修改变量
现在该你来使用变量了。这道练习的注释(以
#
开头的行)提供了创建和修改变量的说明。请在每条注释后面根据说明写一行代码。
注意,这段代码使用了
科学记数法
来定义很大的数字。
4.445e8
等于
4.445 * 10 ** 8
,也就是
444500000.0
。
#代码注释 - 中英对照
单词表:water reservoir 水库;volume:体积;rainfall 降雨;cubic metre 立方米
The current volume of a water reservoir (in cubic metres) 目前水库的蓄水量(单位:立方米)
reservoir_volume = 4.445e8
The amount of rainfall from a storm (in cubic metres) 一场暴雨的降雨量(单位:立方米)
rainfall = 5e6
decrease the rainfall variable by 10% to account for runoff 考虑到流失的水量,将降雨量这个变量降低10%
add the rainfall variable to the reservoir_volume variable 将降雨量与蓄水量相加
increase reservoir_volume by 5% to account for stormwater that flows into the reservoir in the days following the storm 暴雨后的一段时间内,雨水会不断流入水库,考虑这部分水量,需要将水库的蓄水量变量增加 5%
decrease reservoir_volume by 5% to account for evaporation 考虑到雨水蒸发情况,将蓄水量变量减小5%
subtract 2.5e5 cubic metres from reservoir_volume to account for water that's piped to arid regions. 水库里的水会用来浇灌干涸地区,所以需要将蓄水量减少 2.5e5 立方米
print the new value of the reservoir_volume variable 打印蓄水量变量的最新值
Start Quiz:
# The current volume of a water reservoir (in cubic metres)
reservoir_volume = 4.445e8
# The amount of rainfall from a storm (in cubic metres)
rainfall = 5e6
# decrease the rainfall variable by 10% to account for runoff
# add the rainfall variable to the reservoir_volume variable
# increase reservoir_volume by 5% to account for stormwater that flows
# into the reservoir in the days following the storm
# decrease reservoir_volume by 5% to account for evaporation
# subtract 2.5e5 cubic metres from reservoir_volume to account for water
# that's piped to arid regions.
# print the new value of the reservoir_volume variable
更改变量
更改变量会如何影响到用该变量定义的另一个变量?我们来看一个示例。
这是关于山景城人口和人口密度的原始数据。
>>> mv_population = 74728
>>> mv_area = 11.995
>>> mv_density = mv_population/mv_area
现在我们重新定义
mv_population
变量:
( 注意 :后续代码跟在上面三行代码后面,而非重新开始)
>>> mv_population = 75000
变量更改
SOLUTION:
6229SOLUTION:
- `delaware = 1`
- `de = 1`